home *** CD-ROM | disk | FTP | other *** search
- //____________________________________________________________
- // InputSpeech.c
- //
- // Copyright © Dan Parks Sydow, 1995
- // From the book:
- // "Graphics and Sound Programming Techniques for the Mac",
- // M&T Books, 1995
-
-
- //____________________________________________________________
-
- #include <Speech.h>
-
-
- //____________________________________________________________
-
- void InitializeToolbox( void );
- Boolean IsSpeechAvailable( void );
- void OpenSpeechDialog( void );
-
-
- //____________________________________________________________
-
- #define rSpeechDialog 128
- #define kSpeakButton 1
- #define kQuitButton 2
- #define kPhraseEdit 3
-
-
- //____________________________________________________________
-
- void main( void )
- {
- Boolean speechPresent;
-
- InitializeToolbox();
-
- speechPresent = IsSpeechAvailable();
- if ( speechPresent == false )
- ExitToShell();
-
- OpenSpeechDialog();
- }
-
-
- //____________________________________________________________
-
- void OpenSpeechDialog( void )
- {
- DialogPtr theDialog;
- short theItem;
- Boolean allDone = false;
- short theType;
- Handle theHandle;
- Rect theRect;
- Str255 theString;
- OSErr theError;
-
- theDialog = GetNewDialog( rSpeechDialog, nil, (WindowPtr)-1L );
- ShowWindow( theDialog );
- SetPort( theDialog );
-
- while ( allDone == false )
- {
- ModalDialog( nil, &theItem );
-
- switch ( theItem )
- {
- case kSpeakButton:
- GetDialogItem( theDialog, kPhraseEdit, &theType, &theHandle, &theRect );
- GetDialogItemText( theHandle, theString );
- theError = SpeakString( theString );
- if ( theError != noErr )
- ExitToShell();
- break;
-
- case kQuitButton:
- allDone = true;
- break;
- }
- }
-
- DisposeDialog( theDialog );
- }
-
-
- //____________________________________________________________
-
- Boolean IsSpeechAvailable( void )
- {
- OSErr theError;
- long theResult;
- Boolean speechAvail;
-
- theError = Gestalt( gestaltSpeechAttr, &theResult );
- if ( theError != noErr )
- ExitToShell();
-
- speechAvail = theResult & ( 1 << gestaltSpeechMgrPresent );
- if ( speechAvail > 0 )
- return ( true );
- else
- return ( false );
- }
-
-
- //____________________________________________________________
-
- void InitializeToolbox( void )
- {
- InitGraf( &qd.thePort );
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs( 0L );
- FlushEvents( everyEvent, 0 );
- InitCursor();
- }
-
-
-
-